package com.vallis.asfc.controller;


import cn.hutool.core.util.IdcardUtil;
import com.vallis.asfc.entity.User;
import com.vallis.asfc.service.HxPeopleService;
import com.vallis.asfc.service.UserService;
import com.vallis.asfc.util.NativePlace;
import com.vallis.asfc.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author vallis
 * @since 2020-07-22
 */
@Controller
@RequestMapping("/hx-people")
public class HxPeopleController {
    @Autowired
    private HxPeopleService hxPeopleService;
    @Autowired
    private UserService userService;
    @GetMapping("/doIni")
    public Result doIni(){
        User admin=new User();
        admin.setUserName("admin");
        admin.setUserCertnumber("41070319920826203x");
        userService.save(admin);
        hxPeopleService.list().forEach(item->{
            
            User u=new User();
           
            u.setUserName(item.getName())
                    .setUserSnNumber(item.getSn())
                    .setUserPassword("asfchn.cn")
                    .setUserDeptId((long)item.getBelongTeam())
                    .setUserCity(item.getCity())
                    .setUserCertnumber(item.getCertNumber());
            u.setUserAge(IdcardUtil.getAgeByIdCard(item.getCertNumber()) );
            int nativePlaceCode=Integer.parseInt(item.getCertNumber().substring(0, 6));
            u.setUserCity(NativePlace.getNativePlace(nativePlaceCode));
            u.setUserGender(IdcardUtil.getGenderByIdCard(item.getCertNumber()));
            u.setUserDeptName(item.getTeamName());
            userService.save(u);
            
                }
                
                
                
                
                
                
        );
        
        return new Result(new String("success"));
    }
    
}
